// 用户模型
const { User } = require('../../../models/user');
// 统一数据返回类
const { DataReturn } = require('../../../common/returnclass');

/**
 * @api {Put} /users/:id 修改用户
 * @apiGroup Admin-Users
 *
 * @apiParam {ObjectId} id 用户id
 * @apiParam {String} receiving_address 收货地址
 * @apiParam {Number} mobile 手机号
 * 
 * @apiSuccess {Number} code 状态码
 * @apiSuccess {Object} data 返回数据
 * @apiSuccess {String} msg  返回消息
 */
module.exports = async (req, res) => {
	// 用户id 用户状态
	let { id } = req.params;
	let { receiving_address, mobile } = req.fields;
	console.log(id, req.fields);
	// 更新用户状态
	User.updateOne({ _id:id }, { receiving_address, mobile })
	.then(async (result)=>{
		DataReturn.getData(res, 200, [] , '更新用户信息成功');
	}).catch(()=>{
		DataReturn.getData(res, 400, [], '更新用户信息失败');
	})

}
